package com.everfro.codeshare.views;

import java.util.Calendar;
import java.util.Date;
import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Properties;

public class HistoryItem {

	private Properties propertyfile;
	private String originalFilePath;
	
	public HistoryItem(Properties propertyfile, String filepath) {
		super();
		this.propertyfile = propertyfile;
		this.originalFilePath = filepath;
	}
	
	
	public String toString(){
		String displayName  = propertyfile.getProperty("submitted");
		if(propertyfile.getProperty("comment").length() > 0){
			displayName = displayName +  " " + propertyfile.getProperty("comment");
		}
		return displayName;
	}
	
	public String getURL(){
		return propertyfile.getProperty("url");
	}

	public boolean hasExpired(){
		//Check whether the item has expired compared to now
		String expires = this.propertyfile.getProperty("expires");
		
		DateFormat importDateFormat = new SimpleDateFormat("yy-MM-dd");
		
		Date expiresDate = null;
		Date now = new Date();
		boolean b = false;
		try {
			expiresDate = importDateFormat.parse(expires);
			Calendar exCalendar = Calendar.getInstance();
			exCalendar.setTime(expiresDate);
			
			Calendar nowCalendar = Calendar.getInstance();
			nowCalendar.setTime(now);
			
			b = exCalendar.before(nowCalendar);
			
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		
		
		
		
		return b;
	}

	
	
	public String getDescription() {
		String description = this.propertyfile.getProperty("url");
		description += " expires: " + this.propertyfile.getProperty("expires");
		description += " comments: " + this.propertyfile.getProperty("comment");
		// TODO Auto-generated method stub
		return description;
	}


	public String getOriginalFile() {
		return originalFilePath;
	}
}
